home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / A / AE Sample (TC5) / File.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-10  |  2.1 KB  |  66 lines  |  [TEXT/KAHL]

  1. /* File.c */
  2.  
  3. #include    "AESimple.h"
  4.  
  5. Boolean select_file (FSSpec *theFile)
  6. /* Get an FSSpec for the selected file. I'm feeling lazy, so I'll use the        */
  7. /* new StandardGetFile call, which returns an FSSpec. You can do the same         */
  8. /* thing under System 6 by calling SFGetFile and then using HGetCatInfo           */
  9. /* to convert the working directory ID to a volume & dir ID.                      */
  10. {
  11.     SFTypeList typeList = {'PICT', '    ', '    ', '    '};
  12.     StandardFileReply     reply;
  13.     
  14.     StandardGetFile(NIL, 1, typeList, &reply);
  15.     if (reply.sfGood) 
  16.         *theFile = reply.sfFile;
  17.  
  18.     return reply.sfGood;
  19. } /* select_file */
  20.  
  21.  
  22. OSErr open_selected_file (FSSpec *theFile, WindowPtr wp)
  23. /* This routine opens the specified file and reads it into the specified window */
  24. /*                                                                                */
  25. /* If you're working with System 7, your file read routine should take an FSSpec*/
  26. /* as you won't be given a working directory.                                    */
  27. /*                                                                                */
  28. /* If you need to work with both System 6 and System 7, you should use HOpen in */
  29. /* place of FSpopenDF (and _still_ create an FSSpec, which you feed to HOpen as */
  30. /* 3 seperate parameters.                                                        */
  31. /*                                                                                */
  32. /* Note that we're reading in a PICT without spooling it in -- see TN #154 for  */
  33. /* the details on how to read in large pictures.                                */
  34. {
  35.     wiHand    info;
  36.     OSErr    err = noErr;
  37.     short   refNum    = 0;
  38.     long    logEOF    = 0;
  39.     Handle    buffer;
  40.     
  41.     if (wp != NIL) {
  42.         info = (wiHand)GetWRefCon(wp);
  43.         err = FSpOpenDF(theFile, fsRdPerm, &refNum);    /* New System 7 call. */
  44.         if (err == noErr) {
  45.             err = GetEOF(refNum, &logEOF);
  46.             if (logEOF > 512) {
  47.                 buffer = NewHandle(logEOF - 512);
  48.                 MoveHHi(buffer);
  49.                 HLock(buffer);
  50.                 err = SetFPos(refNum, fsFromStart, 512); /* Skip over the header */
  51.                 err = FSRead(refNum, &logEOF, *buffer);
  52.                 HUnlock(buffer);
  53.                 if ((*info)->thePicture == NIL)
  54.                     KillPicture((*info)->thePicture);
  55.                 (*info)->thePicture = (PicHandle)buffer;
  56.             }
  57.             err = FSClose(refNum);
  58.             refNum = 0;
  59.             (*info)->picBounds = (*(*info)->thePicture)->picFrame;
  60.             SetWTitle(wp, theFile->name);
  61.             SetScrollMaxima(wp, info, TRUE);
  62.         }
  63.     }
  64.     
  65.     return err;
  66. } /* open_selected_file */